import redis

class myredis():
    def __init__(self):
        self.conn = redis.Redis(host="localhost",port=6379)

    def str_set(self,key,value,time=None):
        if time:
            self.conn.setex(key,time,value)
        else:
            self.conn.set(key,value)

    def str_get(self,key):
        return self.conn.get(key)

    def insert_values(self,key,value):
        for i in value:
            self.conn.sadd(key,i)

    def get_values(self,key):
        lst = []
        for i in self.conn.smembers(key):
            lst.append(str(i,encoding="utf8"))
        return lst

    def hset_key(self,key,key1,value):
        self.conn.hset(key,key1,value)

    def hget_keys(self,key):
        return self.conn.hgetall(key)

    def hget_key(self,key,key1):
        return self.conn.hget(key,key1)

    def hdel(self,key,key1):
        self.conn.hdel(key,key1)


r = myredis()
# r.insert_values("interface1",["/role"])
# print(r.get_values("interface1"))
# r.hset_key("abac","time","['2021-12-20','2022-1-20']")
# res = str(r.hget_key("abac", "time"),encoding="utf8")
# if "2021-12-11" < res[0]:
#     print(1)
# else:
#     print(2)
